pkgname=searx-qt
pkgver=0.6.0
pkgrel=1
pkgdesc="Desktop client application for Searx/SearXNG/searx-space"
maintainer="CYBERDEViL"
arch="all"
url="https://notabug.org/CYBERDEViL/searx-qt"
license=("GPL3")
depends=("python3-requests" "python3-pyqt5" "python3-jsonschema" "python3-bs4")
optdepends=(
    "python3-pysocks: socks proxy support"
    "python3-pillow: thumbnail support")
makedepends=("gettext" "qtbase5-dev-tools" "python3-build" "python3-installer"
             "python3-wheel" "python3-setuptools")
provides=("searx-qt")
conflicts=("searx-qt")
source=()
sha512sums=()

pkgver() {
    if [[ ! -d "${pkgname}" ]]; then
        # This happends the first time in this hacky DEBBUILD
        echo "${pkgver}"
        return
    fi

    cd "${pkgname}"

    # Are we on a tagged commit?
    git describe --exact-match HEAD >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        # We not have checkedout a tag, return short commit hash.
        echo "${pkgver}-$(git rev-parse --short=7 HEAD)"
        return 0;
    fi

    # This will print the tag name
    git describe --tags --abbrev=0
}

prepare() {
    ln -s $(realpath ${ROOT}/../../../) "${srcdir}/${pkgname}"
    cd ${srcdir}
    pkgver=$(pkgver)
    sed -i "s/__git__ = '.*'/__git__ = '$(pkgver)'/g" ${pkgname}/searxqt/version.py
    sed -i "s/Version=.*/Version=$(pkgver)/g" ${pkgname}/share/searx-qt.desktop
}

build() {
    cd "$srcdir/$pkgname"
    make
}

package() {
    cd "$srcdir/$pkgname"
    make DESTDIR="$pkgdir" install
}
